﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyDBconnection;
using System.Data.Odbc;

namespace CamposInventory
{
    public partial class frmlogin : Form
    {
        FrmMain parent;
        DatabaseConnection dbcon = new DatabaseConnection();
        
        
        public frmlogin(FrmMain p)
        {
            parent = p;
            InitializeComponent();
            btnLogin.Click += new EventHandler(btnLogin_Click);
            checkBox1.CheckStateChanged += new EventHandler(checkBox1_CheckStateChanged);
            
        }

        void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                frmConnection frmcon = new frmConnection();
                frmcon.Show();
            
            
            
            }
        }
       

        void btnLogin_Click(object sender, EventArgs e)
        {
            dbcon.dbconnection();
            dbcon.mylogin("SELECT * from tbluser WHERE Username = '" + txtusername.Text + "' and Password= '" + this.txtpass.Text + "'");
            if (dbcon.tbl.Rows.Count > 0)
            {
                MessageBox.Show("Login Successful","Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
                string accesslevel = dbcon.tbl.Rows[0]["Level"].ToString();
                parent.mnuManupulate(accesslevel);
                string online = txtusername.Text;
                parent.passdata("Welcome : " + online);
                this.Close();
            }
            else
            {
                MessageBox.Show("Invalid Username or Password");
                txtusername.Text = "";
                txtpass.Text = "";
                txtusername.Focus();
                
            }
            dbcon.DBClose();
            }
       
           
               
            }
                
            
             
        }


    

